package in.srain.cube.util.log;

import android.util.Log;

import in.srain.cube.util.CLog;
import in.srain.cube.util.CLogHandler;
import in.srain.cube.util.DLog;
import in.srain.cube.util.NetworkStatusManager;

public class LogProxy implements CLogHandler {

    static private LogProxy instance;

    private DLog mPlainLog;

    private LogProxy() {
        mPlainLog = new DLog();
    }

    public DLog getPlainLog() {
        return mPlainLog;
    }

    public static LogProxy getInstance() {
        if (null == instance) {
            synchronized (LogProxy.class) {
                if (null == instance) {
                    instance = new LogProxy();
                }
            }
        }
        return instance;
    }

    public void logEvent(String eventCat, String eventName, Object data) {
        checkLogValve();
        LogServant.getInstance().writeLogAsync(eventName, data);
        // only in debug we display the event data
        if (CLog.getLevel() > CLog.LEVEL_DEBUG) {
            return;
        }
        if (data == null) {
            Log.i(eventCat, eventName);
        } else {
            Log.i(eventCat, eventName + " " + data.toString());
        }
    }

    private void checkLogValve() {
        // TODO: 2018/5/7 udpate 
        final int networkType = NetworkStatusManager.getInstance().getNetworkType();
        int threshold;
        if (networkType == NetworkStatusManager.NETWORK_CLASS_WIFI || networkType == NetworkStatusManager.NETWORK_CLASS_4G) {
            threshold = 100;
        } else {
            threshold = 200;
        }
        LogServant.getInstance().setShouldSaveThreshold(threshold);
    }

    @Override
    public void v(String tag, String msg) {
    }

    @Override
    public void v(String tag, String msg, Throwable throwable) {
    }

    @Override
    public void d(String tag, String msg) {
    }

    @Override
    public void d(String tag, String msg, Throwable throwable) {
    }

    @Override
    public void i(String tag, String msg) {
    }

    @Override
    public void i(String tag, String msg, Throwable throwable) {
    }

    @Override
    public void w(String tag, String msg) {
    }

    @Override
    public void w(String tag, String msg, Throwable throwable) {
    }

    @Override
    public void e(String tag, String msg) {
    }

    @Override
    public void e(String tag, String msg, Throwable throwable) {
    }

    @Override
    public void f(String tag, String msg) {
    }

    @Override
    public void f(String tag, String msg, Throwable throwable) {
    }
}
